﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace GH.Web.Common
{
    public partial class SelectUnion : BasePage.PageBase
    {
        static string UnitRoot = System.Configuration.ConfigurationSettings.AppSettings["UnitRoot"];
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                TreeViewInit();
            }
        }


        private void TreeViewInit()
        {
            trvUnion.Nodes.Clear();
            TreeNode Root = new TreeNode(UnitRoot, "-1");
            GH.BLL.Union unionBll = new GH.BLL.Union();
            TreeNode tNode;
            //DataTable dtQuery = unionBll.GetAllList().Tables[0];

            string strWhere = string.Empty;
            strWhere += " 1=1";
            //汇总权限
            if (!GetRight(301))
            {
                strWhere += "AND  ID=" + this.Session["Union"].ToString();
            }
             DataTable dtQuery = unionBll.GetList(strWhere).Tables[0];
            if (dtQuery.Rows.Count != 0)
            {
                for (int i = 0; i < dtQuery.Rows.Count; i++)
                {
                    tNode = new TreeNode();
                    tNode.Text = dtQuery.Rows[i]["单位名称"].ToString();
                    tNode.Value = dtQuery.Rows[i]["ID"].ToString();
                    //trvUnion.Nodes.Add(tNode);
                    Root.ChildNodes.Add(tNode);
                }
                trvUnion.Nodes.Add(Root);
                trvUnion.Nodes[0].Select();
            }
        }

        protected void trvUnion_SelectedNodeChanged(object sender, EventArgs e)
        {
            //选择单位
            int depth = trvUnion.SelectedNode.Depth;
            if (depth == 1)
            {
                this.Session["UnionSelect"] = this.trvUnion.SelectedNode.Value;
                this.ExecuteJs("window.close();");
            }
        }

    }
}
